package group.Service.Impl;

import group.Service.RabbitmqService;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Ulegal on 2017/12/13.
 */
@Service("RabbitmqSeiviceImpl")
public class RabbitmqSeiviceImpl implements  RabbitTemplate.ConfirmCallback,RabbitmqService,RabbitTemplate.ReturnCallback {


    @Autowired
    private AmqpTemplate amqpTemplate;

    @Autowired
    RabbitTemplate rabbitTemplate;


    public void RabbitmqActivity(){

        amqpTemplate.convertAndSend("rabbitmqkey","Hello World RabbitMq 实现消息回调");
        rabbitTemplate.setConfirmCallback(this);
        rabbitTemplate.setReturnCallback(this);

    }

    /**
     *  消息回调
     * @param correlationData
     * @param b
     * @param s
     */
    @Override
    public void confirm(CorrelationData correlationData, boolean b, String s) {

       if (b == true){
           System.out.println("消息发送成功！！！");
       }else {
           System.out.println("消息发送失败！！！！");
       }

    }


    @Override
    public void returnedMessage(Message message, int i, String s, String s1, String s2) {
        System.out.println("return--message:");
    }




}
